﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace APILocawebGateway.HTMLHelper
{
    internal abstract class IFormControl
    {
        private string name;

        protected string Name
        {
            get { return name; }
            set { name = value; }
        }
        private string value;

        protected string Value
        {
            get { return this.value; }
            set { this.value = value; }
        }

        public abstract String Render();

        public IFormControl()
        {

        }
        public IFormControl(String name, String value)
        {
            this.Name = name;
            this.value = value;
        }
    }

    internal class Form
    {
        private string action;

        public string Action
        {
            get { return action; }
            set { action = value; }
        }
        private string method;

        public string Method
        {
            get { return method; }
            set { method = value; }
        }
        private string name;

        public string Name
        {
            get { return name; }
            set { name = value; }
        }

        private List<IFormControl> controls;
        public void AddControl(IFormControl control)
        {
            controls.Add(control);

        }
        public Form(String action, String method, String name)
        {
            Action = action;
            Method = method;
            Name = name;
            controls = new List<IFormControl>();
        }

        public String Render()
        {
            StringBuilder form = new StringBuilder();
            form.Append("<form name='" + Name + "' method='" + Method + "' action='" + Action + "' target='_blank'>");
            foreach (IFormControl item in controls)
                form.Append(item.Render());

            form.Append("</form>");
            return form.ToString();

        }



    }

    #region controles de formulario
    internal class InputHidden : IFormControl
    {

        public InputHidden()
            : base()
        {

        }
        public InputHidden(String name, String value)
            : base(name, value)
        {

        }
        public override String Render()
        {
            return "<input type='hidden' name='" + Name + "' ID='" + Name + "' value='" + Value + "'></input>";

        }

    }
    internal class LinkLabel : IFormControl
    {
        string url;
        public LinkLabel(String name, String text, String url)
            : base(name, text)
        {
            this.url = url;
        }
        public override string Render()
        {
            return "&nbsp;&nbsp;&nbsp;&nbsp;<a Href='" + url + "' name='" + Name + "' ID='" + Name + "' target='_blank'>" + Value + "</a>";
        }

    }
    internal class LineSeparator : IFormControl
    {
        public LineSeparator()
            : base()
        {

        }
        public override string Render()
        {
            return "<br>";
        }


    }
    internal class PaymentMethodImage : IFormControl
    {
        Int32? width;
        Int32? height;
        public PaymentMethodImage(String name, String src, Int32? width, Int32? height)
            : base(name, src)
        {
            this.width = width;
            this.height = height;
        }
        public PaymentMethodImage()
        {

        }
        public override String Render()
        {
            String html = String.Empty;
            if (width.HasValue && height.HasValue)
                html = "<input type='image' src='" + Value + "' style='width:" + width + "px;height:" + height + "px;' value='Submit' alt='Submit' />";
            else
                html = "<input type='image' src='" + Value + "' value='Submit' alt='Submit' />";
            return html;

        }
    }
    #endregion


}
